package com.ticket.sass.admin.controller;


import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.admin.annotation.Loggable;
import com.ticket.sass.admin.annotation.Module;
import com.ticket.sass.admin.business.BannerBusiness;
import com.ticket.sass.admin.business.impl.BannerBusinessImpl;
import com.ticket.sass.admin.dto.input.banner.BannerAddInput;
import com.ticket.sass.admin.dto.input.banner.BannerListInput;
import com.ticket.sass.admin.dto.input.banner.BannerUpdInput;
import com.ticket.sass.admin.dto.output.banner.BannerListOutput;
import com.ticket.sass.admin.model.PageModel;
import com.ticket.sass.admin.model.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 横幅控制层
 * @author ywb
 * @date 2021-11-25 14:44
 */
@RestController
@ApiSupport(order = 788)
@Api(tags = {"横幅数据-模块"})
@RequestMapping("/banners")
public class BannerController {

    final BannerBusiness business;
    
    public BannerController(BannerBusinessImpl business) {
        this.business = business;
    }
    
    @GetMapping
    @ApiOperation("横幅列表")
    public ResultModel<PageModel<BannerListOutput>> getBanner(
        @Valid BannerListInput input
    ) {
        return ResultModel.success(
            business.list(input)
        );
    }
    
    @PostMapping
    @ApiOperation("新增")
    @Loggable(module = Module.BANNER, desc = "新增横幅")
    public ResultModel<String> add(
        @RequestBody @Valid BannerAddInput input
    ) {
        business.add(input);
        return ResultModel.success();
    }
    
    @PutMapping
    @ApiOperation("修改")
    @Loggable(module = Module.BANNER, desc = "修改横幅")
    public ResultModel<String> upd(
        @RequestBody @Valid BannerUpdInput input
    ) {
        business.upd(input);
        return ResultModel.success();
    }
}
